Skip to content

Fix 32-bit time_t compile errors in DLTv2 timestamp code#856

Open
xl4hub wants to merge 1 commit into
COVESA:masterfrom
xl4hub:fix/32bit-time_t
Open

Fix 32-bit time_t compile errors in DLTv2 timestamp code#856
xl4hub wants to merge 1 commit into
COVESA:masterfrom
xl4hub:fix/32bit-time_t

Conversation

@xl4hub
Copy link
Copy Markdown

@xl4hub xl4hub commented Apr 22, 2026

Summary

On platforms where time_t is 32-bit (e.g. armv7 Linux with default _FILE_OFFSET_BITS), several DLTv2 timestamp call sites trigger -Werror=shift-count-overflow, -Werror=sign-conversion, or -Werror=sign-compare, preventing compilation with the -Werror flags the project sets in its top-level CMakeLists.txt.

Fixes

  • ts.tv_sec >> 32 (9 sites across dlt-daemon.c, dlt_daemon_client.c, dlt_client.c, dlt_user.c, dlt_common.c) — cast ts.tv_sec to uint64_t before the shift. On 32-bit time_t the shift was undefined behavior; on ARM it silently wrapped to >> 0 due to the 5-bit shift-count mask, which meant seconds[0] in the 40-bit DLTv2 timestamp carried a duplicate of the low byte instead of the expected 0. After the cast the top byte is correctly 0 on 32-bit platforms. No behavior change on 64-bit platforms.

  • time_t tt = msg->storageheader->seconds (dlt_common.c:1084) — explicit (time_t) cast to silence -Wsign-conversion when time_t is signed 32-bit and storageheader->seconds is uint32_t.

  • st.st_size > UINT_MAX (dlt_user.c:5620) — cast st.st_size to uintmax_t for the comparison to avoid -Wsign-compare between off_t (signed long) and unsigned int. The preceding st.st_size < 0 check still guards the cast.

Test plan

  • Cross-compiled dlt and dlt-daemon for armv7 Linux (glibc, 32-bit time_t) with -Werror -Wfatal-errors -Wconversion -Wshadow -Wundef -Wcast-qual — clean build and install.
  • Verified clean build and install on x86_64 Linux (native, 64-bit time_t).
  • DLTv2 wire-format timestamp verified correct on 32-bit target (top byte = 0).

Supersedes #855 (closed to correct commit authorship).

Author: john@excelfore.com

@xl4hub xl4hub force-pushed the fix/32bit-time_t branch 2 times, most recently from 9920709 to 11ec58a Compare April 22, 2026 16:41
Copy link
Copy Markdown
Collaborator

@minminlittleshrimp minminlittleshrimp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit not yet sign-off

Please do:

git commit --amend --signoff

to perform signoff in commit footer

On platforms where time_t is 32-bit (e.g. armv7/musl, glibc arm with
default _FILE_OFFSET_BITS), several DLTv2 timestamp call sites trigger
-Werror=shift-count-overflow, -Werror=sign-conversion, or
-Werror=sign-compare, preventing compilation.

Fixes:

- ts.tv_sec >> 32 (9 sites in dlt-daemon.c, dlt_daemon_client.c,
  dlt_client.c, dlt_user.c, dlt_common.c): cast to uint64_t before
  shifting. On 32-bit time_t the shift is UB; on 64-bit it is a no-op.
  The top byte of the 40-bit seconds field is now correctly zero on
  32-bit platforms instead of carrying a stray duplicate of the low
  byte (caused by ARM's 5-bit shift-count mask).

- time_t tt = msg->storageheader->seconds (dlt_common.c:1084):
  explicit (time_t) cast to silence sign-conversion when time_t is
  signed 32-bit.

- st.st_size > UINT_MAX (dlt_user.c:5620): cast st.st_size to
  uintmax_t for the comparison, avoiding the signed/unsigned mismatch
  between off_t and unsigned int.

Signed-off-by: john crosbie <john@excelfore.com>
@xl4hub xl4hub force-pushed the fix/32bit-time_t branch from 11ec58a to 98d78ee Compare April 24, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants